//
//  SHD_MainViewController.m
//  B段项目
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 谢美娜. All rights reserved.
//

#import "SHD_MainViewController.h"
#import "SHD_HomeCollectionViewCell.h"
@interface SHD_MainViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, PushViewController, UIScrollViewDelegate>

@end

@implementation SHD_MainViewController
#pragma mark 导航条按钮
- (void)viewDidLoad {
    [super viewDidLoad];

    UIBarButtonItem *homeItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"SHD_shouye"] style:UIBarButtonItemStylePlain target:self action:@selector(button1Action)];

    homeItem.tintColor = [UIColor whiteColor];
    homeItem.tag = 1001;
    UIBarButtonItem *chipTiem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"SHD_suipian"] style:UIBarButtonItemStylePlain target:self action:@selector(button2Action)];
    chipTiem.tintColor = [UIColor whiteColor];
    chipTiem.tag = 1002;
    self.navigationItem.rightBarButtonItems = @[homeItem, chipTiem];
    self.title = @"精品";
    [_SHD_contestTableView NightWithType:UIViewColorType2];
    
}
#pragma mark 协议推界面
-(void)passByValue:(NSString *)index
{
    SHD_DetaViewController *sdv = [[SHD_DetaViewController alloc]init];
    sdv.ID = index;
    [self.navigationController pushViewController:sdv animated:YES];
    
}
-(void)button1Action
{
    UIBarButtonItem *home = (UIBarButtonItem *)[self.view viewWithTag:1001];
    home.tintColor = [UIColor colorWithHue:0.4 saturation:0.42 brightness:0.73 alpha:0.5];
    UIBarButtonItem *chip = (UIBarButtonItem *)[self.view viewWithTag:1002];
    chip.tintColor = [UIColor whiteColor];
    self.title = @"精品";
    [_homeCollectionView setContentOffset:CGPointMake(375 * FitWidth, 0) animated:YES ];
    [_SHD_contestTableView.header beginRefreshing];
    [UIView animateWithDuration:0.3 animations:^{
        _smallLabel.frame = CGRectMake(333 * FitWidth, 0, 27 * FitWidth, 2 * FitHeight);
        //[self.view addSubview:_smallLabel];
    }];
}
-(void)button2Action
{
    UIBarButtonItem *home = (UIBarButtonItem *)[self.view viewWithTag:1001];
    UIBarButtonItem *chip = (UIBarButtonItem *)[self.view viewWithTag:1002];
    chip.tintColor = [UIColor colorWithHue:0.4 saturation:0.42 brightness:0.73 alpha:0.5];
    home.tintColor = [UIColor whiteColor];
    self.title = @"碎片";
       [_homeCollectionView setContentOffset:CGPointMake(0, 0) animated:YES ];
    [_SHD_contestTableView.header beginRefreshing];
    [UIView animateWithDuration:0.3 animations:^{
        _smallLabel.frame = CGRectMake(280 * FitWidth, 0, 27 * FitWidth, 2 * FitHeight);
        // [self.view addSubview:_smallLabel];
    }];
}
#pragma mark HomeCell两个方法
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 2;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 1) {
        
    
    SHD_HomeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"identifier" forIndexPath:indexPath];
        cell.delegata = self;
        cell.nav = self.navigationController;
        
    return cell;
    }
    else
    {
        SHD_ChipCollectionVeiwCell *chipCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"chipIden" forIndexPath:indexPath];
        chipCell.nav = self.navigationController;
        return chipCell;
    }
}
#pragma mark 首页数据
-(void)loadView
{
    [super loadView];
    UICollectionViewFlowLayout *homeFlowLayou = [[UICollectionViewFlowLayout alloc]init];
    homeFlowLayou.itemSize = CGSizeMake(375 * FitWidth, 667  * FitHeight);
    homeFlowLayou.minimumLineSpacing = 0;
    homeFlowLayou.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _homeCollectionView = [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:homeFlowLayou];
    _homeCollectionView.delegate = self;
    _homeCollectionView.dataSource = self;
    _homeCollectionView.pagingEnabled = YES;
    _homeCollectionView.showsHorizontalScrollIndicator = NO;
    [_homeCollectionView registerClass:[SHD_HomeCollectionViewCell class] forCellWithReuseIdentifier:@"identifier"];
    [_homeCollectionView registerClass:[SHD_ChipCollectionVeiwCell class] forCellWithReuseIdentifier:@"chipIden"];
    
    _homeCollectionView.contentOffset = CGPointMake(375 * FitWidth, 0);
    _smallLabel = [[UILabel alloc]initWithFrame:CGRectMake(333 * FitWidth, 0, 27 * FitWidth, 2 * FitHeight)];
    _smallLabel.backgroundColor = [UIColor grayColor];
    
    [_homeCollectionView NightWithType:UIViewColorType2];
    [self.view addSubview:_homeCollectionView];
    [self.view addSubview:_smallLabel];
    
    
}
-(void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row >0) {
        
        [UIView animateWithDuration:0.3 animations:^{
            _smallLabel.frame = CGRectMake(280 * FitWidth, 0, 27 * FitWidth, 2 * FitHeight);
            
        }];
        self.title = @"碎片";
    }
    else
    {
        [UIView animateWithDuration:0.3 animations:^{
            _smallLabel.frame = CGRectMake(333 * FitWidth, 0, 27 * FitWidth, 2 * FitHeight);
            // [self.view addSubview:_smallLabel];
        }];
        self.title = @"精品";

    }

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
